<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        div {
            margin: 150px 350px;
        }

        a {
            position: fixed;
            right: 50%;
            bottom: 5%;
            display: block;
            width: 100px;
            height: 30px;
            background-color: #e38a0e;
            color: #fff;
            text-align: center;
            line-height: 30px;
            text-decoration: none;
        }
    </style>
</head>

<body>
    <script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js"></script>
    <!-- 添加 video 元素 -->
    <div>
        <video id="myVideo" width="640" height="360" controls>
            <source src="/video/屏幕录制 2024-12-28 204616.mp4" type="video/mp4">
            您的浏览器不支持视频播放。
        </video>
    </div>
    <a href="首页.html">返回</a>
    <script>
        const video = document.getElementById('myVideo');
        video.ontimeupdate = _.throttle(() => {
            localStorage.setItem('videoTime', video.currentTime);
        }, 1000)
        video.onloadeddata = () => {
            // const savedTime = localStorage.getItem('videoTime');
            // if (savedTime) {
            //     video.currentTime = parseFloat(savedTime);
            // }
            video.currentTime = localStorage.getItem('videoTime') || 0;
        }

        // // 页面加载时，从 localStorage 中读取播放位置
        // const savedTime = localStorage.getItem('videoTime');
        // if (savedTime) {
        //     video.currentTime = parseFloat(savedTime);
        // }

        // // 节流函数
        // function throttle(func, delay) {
        //     let timer = null;
        //     return function () {
        //         if (!timer) {
        //             func.apply(this, arguments);
        //             timer = setTimeout(() => {
        //                 timer = null;
        //             }, delay);
        //         }
        //     };
        // }

        // // 节流后的保存播放时间函数
        // const saveVideoTime = throttle(() => {
        //     localStorage.setItem('videoTime', video.currentTime);
        // }, 1000); // 每 1 秒保存一次

        // // 监听视频播放时间变化事件，调用节流后的保存函数
        // video.addEventListener('timeupdate', saveVideoTime);
    </script>
</body>

</html>